import request from '@/utils/request'

export const getEDBTables = (params) => {
  return request({
    url: '/v1/datalib/table/',
    method: 'get',
    params,
  })
}

// 查询指标季度数据
export const getDetail = (params) => {
  return request({
    url: '/v1/datalib/table/indexData/',
    method: 'get',
    params,
  })
}

export const addEDBTable = (data) => {
  return request({
    url: '/v1/datalib/table/',
    method: 'post',
    data,
  })
}

// 删除数据指标
export const deleteEDBTable = (data) => {
  return request({
    url: '/v1/datalib/table/',
    method: 'delete',
    data,
  })
}

// 清空一个指标数据
export const brushEDBTable = (data) => {
  return request({
    url: '/v1/datalib/table/brush/',
    method: 'put',
    data,
  })
}

// 查询一个数据表是否存在
export const getEDBIndexExists = (params) => {
  return request({
    url: '/v1/datalib/table/exists/',
    method: 'get',
    params,
  })
}

// 查询一个数据表详情
export const getEDBTableDetail = (params) => {
  return request({
    url: '/v1/datalib/table/info/',
    method: 'get',
    params,
  })
}

// 新建自定义数据指标
export const addCustomEDBTable = (data) => {
  return request({
    url: '/v1/datalib/table/csm/',
    method: 'post',
    data,
  })
}

// 查询自定义数据指标
export const getCustomEDBTable = (params) => {
  return request({
    url: '/v1/datalib/table/csm/',
    method: 'get',
    params,
  })
}

// 使用文件上传自定义指标的数据
export const updateIndexWithFile = (data) => {
  return request({
    url: '/v1/datalib/table/csm/fileUpdate/',
    method: 'post',
    data,
  })
}

// 查询更新自定义数据的状态
export const getFileUpdateState = () => {
  return request({
    url: '/v1/datalib/table/csm/fileManyUpdateState/',
    method: 'get',
  })
}

// 使用文件批量更新自定义数据
export const updateManyIndexesWithFile = (data) => {
  return request({
    url: '/v1/datalib/table/csm/fileManyUpdate/',
    method: 'post',
    timeout: 120000,
    data,
  })
}

// 自定义指标添加数据
export const insertIndexValue = (data) => {
  return request({
    url: '/v1/datalib/table/csm/update/',
    method: 'post',
    data,
  })
}

// 转移数据表
export const moveCustomerIndex = (touser) => {
  return request({
    url: '/v1/datalib/table/csm/transferal/',
    method: 'put',
    data: { touser },
  })
}

// 更新指标内的数据
export const updateIndexValue = (data) => {
  return request({
    url: '/v1/datalib/table/updateValue/',
    method: 'put',
    data,
  })
}

// 删除指标内的数据
export const deleteIndexValue = (data) => {
  return request({
    url: '/v1/datalib/table/deleteValue/',
    method: 'delete',
    data,
  })
}

// 修改数据指标的分类
export const classifyIndex = (data) => {
  return request({
    url: '/v1/datalib/table/classify/',
    method: 'post',
    data,
  })
}

// 请求数据指标的最新值和环比值
export const getFormulaIndexLinkRatio = (data) => {
  return request({
    url: '/v1/datalib/indexAis/linkRatio/',
    method: 'post',
    data,
  })
}

// 查询各组指标数量和占比和详情
export const getIndexGrouper = () => {
  return request({
    url: '/v1/datalib/table/indexGroups/',
    method: 'get',
  })
}

// 查询自定义的公式
export const getMyFormula = (params) => {
  return request({
    url: '/v1/datalib/formula/my/',
    method: 'get',
    params,
  })
}
